package dongshi.daddy.springioc.three.three_three.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component("businessPersonLifecycle")
public class BusinessPersonLifecycle implements
        Person,
        BeanNameAware,
        BeanFactoryAware,
        ApplicationContextAware,
        InitializingBean,
        DisposableBean {

    private Animal animal = null;

    public BusinessPersonLifecycle(@Autowired @Qualifier("dog") Animal animal) {
        System.out.println("实例化和注入");
        this.animal = animal;
    }


    @Override
    public void service() {

    }

    @Override
    public void setAnimal(Animal animal) {

    }

    private String beanName;
    @Override
    public void setBeanName(String name) {
        System.out.println("设置bean name");
        this.beanName = name;
    }

    private BeanFactory beanFactory;
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("设置beanFactory");
        this.beanFactory = beanFactory;
    }

    private ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("设置applicationContext");
        this.applicationContext = applicationContext;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("属性设置完毕了！！！");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("bean销毁了！！！");
    }

    @PostConstruct
    public void init() {
        System.out.println("@PostConstruct注解的初始化方法");
    }

    @PreDestroy
    public void predestory1() {
        System.out.println("@PreDestroy定义的销毁方法");
    }
}
